package com.liqi.deployment.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liqi.common.annotation.DataScope;
import com.liqi.common.core.domain.BaseEntity;
import com.liqi.common.utils.DateUtils;
import com.liqi.deployment.domain.DvDeployment;
import com.liqi.deployment.domain.dto.DvDeploymentStatusCount;
import com.liqi.deployment.mapper.DvDeploymentMapper;
import com.liqi.deployment.service.IDvDeploymentService;
import com.liqi.items.domain.TCfgBranch;
import com.liqi.items.mapper.TCfgBranchMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备投放管理Service业务层处理
 *
 * @author xiaoli
 * @date 2022-02-14
 */
@Service
public class  DvDeploymentServiceImpl  extends ServiceImpl<DvDeploymentMapper, DvDeployment> implements IDvDeploymentService
{
    @Autowired
    private DvDeploymentMapper dvDeploymentMapper;



    /**
     * 查询设备投放管理
     *
     * @param id 设备投放管理主键
     * @return 设备投放管理
     */
    @Override
    public DvDeployment selectDvDeploymentById(Long id)
    {
        return dvDeploymentMapper.selectDvDeploymentById(id);
    }

    @Override
    public DvDeployment selectDvDeploymentByDeviceId(String deviceId) {
        return dvDeploymentMapper.selectDvDeploymentByDeviceId(deviceId);
    }

    /**
     * 给接口使用的方法，只查部署表的数据，不关联查其他表
     * @param deviceId
     * @return 设备投放管理
     */
    @Override
    public DvDeployment getByDeviceId(String deviceId) {
        return dvDeploymentMapper.getByDeviceId(deviceId);
    }

    /**
     * 查询设备投放管理列表
     *
     * @param dvDeployment 设备投放管理
     * @return 设备投放管理
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u", regionAlias = "r", groupAlias = "g")
    public List<DvDeployment> selectDvDeploymentList(DvDeployment dvDeployment)
    {
        return dvDeploymentMapper.selectDvDeploymentList(dvDeployment);
    }
  /**
     * 查询设备投放管理列表
     *
     * @param dvDeployment 设备投放管理
     * @return 设备投放管理
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u", regionAlias = "r", groupAlias = "g")
    public List<DvDeployment> selectDvDeploymentJiankongList(DvDeployment dvDeployment)
    {
        return dvDeploymentMapper.selectDvDeploymentJiankongList(dvDeployment);
    }

    /**
     * 计算各种状态的设备的数量
     * @return
     */
    @Override
    public List<DvDeploymentStatusCount> countDeploymentStatus(String regionId,String groupId,String deploymentName,String deviceId,String branchCode,String brandCode,String deviceStatus) {
        return dvDeploymentMapper.countDeploymentStatus(new BaseEntity(),regionId,groupId,deploymentName,deviceId,branchCode,brandCode,deviceStatus);
    }

    /**
     * 新增设备投放管理
     *
     * @param dvDeployment 设备投放管理
     * @return 结果
     */
    @Override
    public int insertDvDeployment(DvDeployment dvDeployment)
    {
        dvDeployment.setCreateTime(DateUtils.getNowDate());
        return dvDeploymentMapper.insertDvDeployment(dvDeployment);
    }

    /**
     * 修改设备投放管理
     *
     * @param dvDeployment 设备投放管理
     * @return 结果
     */
    @Override
    public int updateDvDeployment(DvDeployment dvDeployment)
    {
        dvDeployment.setUpdateTime(DateUtils.getNowDate());
        return dvDeploymentMapper.updateDvDeploymentByDeviceId(dvDeployment);
    }

    /**
     * 批量删除设备投放管理
     *
     * @param ids 需要删除的设备投放管理主键
     * @return 结果
     */
    @Override
    public int deleteDvDeploymentByIds(Long[] ids)
    {
        return dvDeploymentMapper.deleteDvDeploymentByIds(ids);
    }

    /**
     * 删除设备投放管理信息
     *
     * @param id 设备投放管理主键
     * @return 结果
     */
    @Override
    public int deleteDvDeploymentById(Long id)
    {
        return dvDeploymentMapper.deleteDvDeploymentById(id);
    }
    /**
     * 根据设备名称查询设备投放管理信息
     *
     * @param deviceCodes 设备编号
     * @return 结果
     */
    @Override
    public List<DvDeployment> selectDvDeviceListByDeviceCodes(String[] deviceCodes) {
        return dvDeploymentMapper.selectDvDeviceListByDeviceCodes(deviceCodes);
    }
}
